﻿using KinonekoSoftware.Foundation;

namespace KinonekoSoftware.Platform.Controls
{
    public partial class DialogHost : ContentControl
    {
        public static readonly DependencyProperty DialogProperty;
        public static readonly DependencyProperty IsOpenedProperty;

        static DialogHost()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DialogHost), new FrameworkPropertyMetadata(typeof(DialogHost)));
            IsOpenedProperty = DependencyProperty.Register(nameof(IsOpened),
                typeof(bool),
                typeof(DialogHost),
                new PropertyMetadata(Boxing.False));
            BusyTextProperty = DependencyProperty.Register(
                nameof(BusyText),
                typeof(string),
                typeof(DialogHost),
                new PropertyMetadata(default(string)));
            IsBusyProperty = DependencyProperty.RegisterReadOnly(
                nameof(IsBusy),
                typeof(bool),
                typeof(DialogHost),
                new PropertyMetadata(Boxing.False));

            DialogProperty = DependencyProperty.Register(nameof(Dialog),
                typeof(object),
                typeof(DialogHost),
                new PropertyMetadata(default(object)));

        }
        
        public DialogHost()
        {
            _ViewModelErrorTypeTracker   = new Dictionary<Type, int>();
            _stack = new Stack<DialogBase>();
        }

        
        /// <summary>
        /// 实际对话框内容
        /// </summary>
        public object Dialog
        {
            get => GetValue(DialogProperty);
            private set => SetValue(DialogProperty, value);
        }

        /// <summary>
        /// 
        /// </summary>
        public bool IsOpened
        {
            get => (bool)GetValue(IsOpenedProperty);
            set => SetValue(IsOpenedProperty, Boxing.Box(value));
        }

    }
}